<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class news_type extends CI_Controller {

	function __construct()
	{
		parent::__construct(); 
	  if(!login_user()){
       show_jump('已退出登录', site_url('manage/login/index'));
       }
//	parse_str($_SERVER['QUERY_STRING'], $_GET); //解析链接，直接放到GET中
		$this->load->model('manage/m_news_type');
	}
	function index(){
		if(!IS_POST){	
	    $this->load->library('pagination');
		$config['base_url'] = base_url().'index.php/manage/news_type/index/';		
		$config['total_rows'] =  $this->m_news_type->get_news_type_num();
		$config['per_page'] = '15'; 
        $config['full_tag_open'] = '<p>';   
        $config['full_tag_close'] = '</p>';          
    	$this->pagination->initialize($config); 	
		 //get results   
	    $data['results'] = $this->m_news_type->get_news_type($config['per_page'],$this->uri->segment(4));
	    $data['url']=base_url().'index.php/manage/news_type/';
	//   print_r($data['results']);                                 			
		$this->load->view('manage/news_type_index',$data);  
		}else{
			 $ids=$_POST['ids'];
			 $ids=implode(',',$ids);
			 $ids=trim($ids,',');		
			 $success=$this->m_news_type->batch_delete_news_type($ids);	
	    	if($success){
    	 	 show_jump('删除成功',site_url('manage/news_type/index')) 	;  
    	    }else{   	 	
       	   show_jump('删除失败',site_url('manage/news_type/index')) 	;
    	    }
		}
	}	
	function add(){		
		 if(!IS_POST){	
		 	 $data['act']='add';	 	
		     $this->load->view('manage/news_type_form',$data);
		 }else{
		 	$type_name = trim($this->input->post('type_name'));
		    $is_top= trim($this->input->post('is_top'));
		   $success= $this->m_news_type->save_news_type($type_name,$is_top);
		   if($success){
    	 	 show_jump('删除成功',site_url('manage/news_type/index')) 	;  
    	   }else{   	 	
       	   show_jump('删除失败',site_url('manage/news_type/index')) 	;
    	   }
		 }
	}
	function edit(){
		 $id=$_GET['id'];
	  if(!IS_POST){       
	 	     $data['result']=$this->m_news_type->get_news_type_ById($id);
	 	     $data['act']='edit';	 	
		     $this->load->view('manage/news_type_form',$data);
		 }else{		 	
		 	$type_name = trim($this->input->post('type_name'));
		    $is_top= trim($this->input->post('is_top'));
		    $success=$this->m_news_type->update_news_type($type_name,$is_top,$id);
			 if($success){
	    	 	 show_jump('删除成功',site_url('manage/news_type/index')) 	;  
	    	 }else{   	 	
	       	   show_jump('删除失败',site_url('manage/news_type/index')) 	;
	    	 }
		 }
		  debugit(0);
	}
    function delete_news_type(){
    	 $id=$_GET['id'];
    	 $success= $this->m_news_type->delete_news_type($id);
    	 if($success){
    	 	 show_jump('删除成功',site_url('manage/news_type/index')) 	;  
    	 }else{   	 	
       	   show_jump('删除失败',site_url('manage/news_type/index')) 	;
    	 }
    	
    }
   
}
?>